﻿/*
 * ========================================================================
 * Copyright(c) 2007-2012 情留メ蚊子, All Rights Reserved.
 * Welcom use the LiteFetion.
 * See more information,Please goto http://www.94qing.com
 * ========================================================================
 * 
 * 作 者：情留メ蚊子
 * Q  Q: 540644769
 * 邮 箱：qlwz@qq.com
 * 网 址：http://www.94qing.com
 * ========================================================================
*/
using System;

namespace LiteFetion.Model
{
    /// <summary>
    /// 用户设置的短信策略
    /// </summary>
    /**
     * 飞信用户可以设置不接受飞信发送的短信，也可以设置在几个小时之内不接受短信
     * 字符串形式形如：1.00:00:00	 0.0:0:0 36500.00:00:00，其含义是在多少时间内不接受短信
     * D.H:M:S
     */
    public class SMSPolicy
    {
        public SMSPolicy()
        {
            RefusedSMSDate = DateTime.Now;
        }

        /// <summary>
        /// 拒绝接受短信的时间点，小于这个时间就不接受短信
        /// </summary>
        public DateTime RefusedSMSDate { get; private set; }

        /// <summary>
        /// 当前好友是否短信在线
        /// </summary>
        /// <returns></returns>
        public bool IsSMSOnline
        {
            get
            {
                return (DateTime.Compare(this.RefusedSMSDate, DateTime.Now) <= 0);
            }
        }

        /// <summary>
        /// 解析短信策略字串
        /// </summary>
        /// <param name="sms">sms 短信策略字串</param>
        public void Parse(string sms)
        {
            if (sms == "0.0:0:0")
            {
                this.RefusedSMSDate = DateTime.Now;
            }
            else
            {
                string[] s = sms.Split(".");
                int d = s[0].ToInt();
                DateTime dt = s[1].ToDateTime();
                this.RefusedSMSDate = DateTime.Now.AddDays(d).AddHours(dt.Hour).AddMinutes(dt.Minute).AddMilliseconds(dt.Millisecond);
            }
        }
    }
}
